(function($){
	//slider
	$.fn.sliderShade = function(options){
		
		options = jQuery.extend({
			width: 1200,
			thumb: true,
			current: 0,
			arrow: true,
			speed: 400,
			playtime: 3000
        },
        options);
		
		var _this = this;
		var box_w = $(window).width();
		var _width = options.width-(box_w-options.width)/2;
		var _child = this.children(".box");
		var _len = this.find(".item").length;
		var num = 1;
		
		if(options.arrow){
			var arrow = '';
			arrow += '<div class="shade-left" style="width: '+(box_w-options.width)/2+'px; left: '+-(box_w-options.width)/2+'px;"><a class="prev" href="javascript:;"></a></div>';
			arrow += '<div class="shade-right" style="width: '+(box_w-options.width)/2+'px; right: '+-(box_w-options.width)/2+'px;"><a class="next" href="javascript:;"></a></div>';
			_child.before(arrow);
		}
		
		if(options.thumb){
			var thumb = '';
			this.find(".item").each(function(i){
				if(i==options.current){
					thumb += '<li class="current"></li>';
				}else{
					thumb += '<li></li>';
				}
			});
			this.append('<div class="thumb"><ul>'+thumb+'</ul></div>')
		}
		
		function init(){
			_child.css({
				width:options.width*(_this.find(".item").length+2)+"px"
			});
			var _first = _this.find(".item:first").clone();
			var _last = _this.find(".item:last").clone();
			_first.appendTo(_child);
			_last.prependTo(_child);
		}
		init();

		
		this.find('.thumb ul li').mouseover(function(e){
			num = $(this).index()+1;
			$(this).addClass('current').siblings('li').removeClass('current');
			_child.stop().animate({left:-($(this).index()+1)*options.width},options.speed);
			e.stopPropagation();
		});

		this.find(".prev").live('click',function(){
			if(_child.is(":animated")) return false;
			num--;
			if(num<1){
				num=_len;
				_child.css({left:-(_len+1)*options.width+"px"});
				_child.animate({left:-num*options.width},options.speed);
			}else{
				_child.animate({left:-num*options.width},options.speed);
			}
			_this.find('.thumb ul li').eq(num-1).addClass('current').siblings('li').removeClass('current');
			return false;
		});
		
		this.find(".next").live('click',function(){
			if(_child.is(":animated")) return false;
			num++;
			if(num>_len){
				num=1;
				_child.css({left:"0"});
				_child.animate({left:-num*options.width},options.speed);
			}else{
				_child.animate({left:-num*options.width},options.speed);
			}
			_this.find('.thumb ul li').eq(num-1).addClass('current').siblings('li').removeClass('current');
			return false;
		});
		
		var interval = setInterval(autoPlay,options.playtime);
		
		this.parent().hover(function(){
			clearInterval(interval);
		},function(){
			interval = setInterval(autoPlay,options.playtime);
		});
		
		function autoPlay(){
			if(num>_len-1) num = 0;
			_this.find('.thumb ul li').eq(num).trigger("mouseover");
		}
		
	}


	$.tips = function(options){
		var defaults = {
			icon: 'normal',
			content: '成功！',
			callback: function(){}
		};
		var sets = $.extend(defaults,options||{});
		var id = parseInt(Math.random()*100);
		var tip = '<div class="tips" id="tip_'+id+'">';

		tip += '<div class="'+ sets.icon +'"><span><b></b>'+sets.content+'</span></div>';
		
		$('body').append(tip);
		$("#tip_"+id).css({marginLeft:-$("#tip_"+id).width()/2}).fadeIn(300)
		setTimeout(function(){
			$("#tip_"+id).animate({opacity:'0'},300,function(){
				$("#tip_"+id).remove();
				sets.callback(true);
				return false;
			});
		},1500);
	}

	//倒计时插件，使用时间戳
	$.fn.timer = function(){
		var $this = $(this);
		window.setInterval(function(){
			$this.each(function(){
				var timer = $(this).data("time");//总时间
				if(timer<=0) return false;
				timer--;
				var d = parseInt(timer/3600/24);
			    var h = parseInt(timer/3600%24);
			    var m = parseInt(timer%3600/60);
			    var s = timer%60;
			    $(this).children(".d").text((d>9?d:"0"+d));
			    $(this).children(".h").text((h>9?h:"0"+h));
			    $(this).children(".m").text((m>9?m:"0"+m));
			    $(this).children(".s").text((s>9?s:"0"+s));
				$(this).data("time",timer)
			});
		},1000);
	}
	
	$.dialogTip = function(options){
		var options = jQuery.extend({
			content: '提示信息内容',
			title: '提示信息',
			cancelText: '关闭'
        },
        options);
		top.dialog({
			content : '<div class="padding-large">'+options.content+'</div>',
			title: options.title,
			fixed: true,
			cancelValue: options.cancelText,
			cancel: function(){}
		}).showModal();
	}
	
	$.dialogConfirm = function(options){
		var options = jQuery.extend({
			content: '提示信息内容',
			title: '提示信息',
			callback: function(){
				
			}
        },
        options);
        top.dialog({
			content : '<div class="padding-large">'+options.content+'</div>',
			title: options.title,
			fixed: true,
			okValue: '确定',
			ok: function(){
				options.callback(1);
			},
			cancelValue: '取消',
			cancel: function(){}
		}).showModal();
	}
	
})(jQuery)
























